﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class BulletMgr {

    protected List<Bullet> _bulletList = null;
    public void Init() {
        _bulletList = new List<Bullet>();
    }

    public void Tick() {
        foreach (Bullet bullet in _bulletList) {
            bullet.Tick();
        }
        BulletInvalidClean();
    }

    public bool AddBullet(Bullet bullet) {
        if (!bullet) return false;

        _bulletList.Add(bullet);
        bullet.transform.parent = GameScene.instance.transform;
        return true;
    }

    // 无效的子弹消除
    public void BulletInvalidClean() {
        for (int i = _bulletList.Count - 1; i >= 0; i--) {
            if (_bulletList[i].isValid == false) {
                _bulletList[i].BulletDestroy();
                _bulletList.RemoveAt(i);
            }
        }
    }
}
